import Vue from "vue";
import Router from "vue-router";

Vue.use(Router);


export const constantRouterMap = [{
  path: "/",
  name: "home",
  component: resolve => {
    require(["./views/Home.vue"], resolve);
  }
}]

//实例化vue的时候只挂载constantRouter
export default new Router({
  mode: "history",
  routes: constantRouterMap
});

//异步挂载的路由
//动态需要根据权限加载的路由表 
export const asyncRouterMap = [{
      path: "/mains",
      name: "mains",
      meta: { role: ['admin','svip'] }, 
      component: resolve => {
        require(["./views/Mains.vue"], resolve);
      },
      children: [{
          path: "/system",
          name: "system",
          component: resolve => {
            require(["./views/System.vue"], resolve);
          }
        },
        {
          path: "/goods",
          name: "goods",
          component: resolve => {
            require(["./views/Goods.vue"], resolve);
          }
        },
        {
          path: "/user",
          name: "user",
          component: resolve => {
            require(["./views/User.vue"], resolve);
          }
        },
        {
          path: "/activity",
          name: "activity",
          component: resolve => {
            require(["./views/Activity.vue"], resolve);
          }
        },
        {
          path: "/userlist",
          name: "userlist",
          component: resolve => {
            require(["./views/Userlist.vue"], resolve);
          }
        },
        {
          path: "/userinfo",
          name: "userinfo",
          component: resolve => {
            require(["./views/UserInfo.vue"], resolve);
          }
        },
        {
          path: "/goods",
          name: "goods",
          component: resolve => {
            require(["./views/Goods.vue"], resolve);
          }
        },
        {
          path: "/goodslist",
          name: "goodslist",
          component: resolve => {
            require(["./views/Goodslist.vue"], resolve);
          }
        },
        {
          path: "/sort",
          name: "sort",
          component: resolve => {
            require(["./views/Sort.vue"], resolve);
          }
        },
        {
          path: "/sortlist",
          name: "sortlist",
          component: resolve => {
            require(["./views/Sortlist.vue"], resolve);
          }
        },
        {
          path: "/orderlist",
          name: "orderlist",
          component: resolve => {
            require(["./views/Orderlist.vue"], resolve);
          }
        },
        {
          path: "/order",
          name: "order",
          component: resolve => {
            require(["./views/Order.vue"], resolve);
          }
        },
      ]
    },
    {
      path: "/about",
      name: "about",
      meta: { role: ['admin','svip'] }, 
      component: resolve => {
        require(["./views/About.vue"], resolve);
      }
    },
    {
      path: "/pptshop",
      name: "pptshop",
      meta: { role: ['admin','svip'] }, 
      component: resolve => {
        require(["./views/Pptshop.vue"], resolve);
      }
    },
  {
    path: '*',
    redirect: '/404',
    hidden: true
  }
];